package org.anupta.realm.main;

import org.anupta.realm.server.inter.InterServer;
import org.anupta.realm.server.realm.RealmServer;
import org.anupta.realm.utils.others.Config;
import org.anupta.realm.utils.others.ErrorLogger;
import org.anupta.realm.utils.others.OutLogger;
import org.anupta.realm.utils.others.TimerThread;
import org.anupta.realm.utils.sql.Database;
import org.anupta.realm.utils.sql.Sql;

public class Main {
    public static ErrorLogger err = new ErrorLogger();
    public static OutLogger out = new OutLogger();
    public static RealmServer realm = new RealmServer();
    public static InterServer inter = new InterServer();

    public static void main(String[] args) {
    	Runtime.getRuntime().addShutdownHook(new Thread()
		{
			public void run()
			{
				close();
			}});
    	long time = System.nanoTime();
    	Config.readConfig("config.xml");
		Database.getDatabase(Config.DRIVER, Config.LOGIN[0], Config.LOGIN[1], Config.LOGIN[2]);
		Database.getDatabase(Config.DRIVER, Config.LOGIN_REALM[0], Config.LOGIN_REALM[1], Config.LOGIN_REALM[2]);
        Sql.setAllDAO();
        realm.bind(Config.REALM_PORT);
        inter.bind(Config.INTER_PORT);
        new TimerThread();
        out.println("Started in : " + (System.nanoTime() - time) + " nanoseconds");
    }

    public static void close(){
        err.close();
        out.close();
    }
}